<template>
  <div>
    <van-cell title="搜索历史">
      <div v-if="isDelete">
        <span @click="$emit('clear')">全部删除</span>
        <span class="black"> </span>
        <span @click="isDelete = false">完成</span>
      </div>
      <van-icon name="delete" v-else @click="isDelete = true" />
    </van-cell>
    <van-cell
      :title="item"
      v-for="(item, index) in searchHisList"
      :key="index"
      @click="cellClick(item, index)"
    >
      <van-icon name="close" v-show="isDelete" />
    </van-cell>
  </div>
</template>

<script>
export default {
  props: ['searchHisList'],
  data () {
    return {
      isDelete: false
    }
  },

  created () {},

  methods: {
    cellClick (item, index) {
      if (this.isDelete) {
        this.searchHisList.splice(index, 1)
      } else {
        this.$emit('search', item)
      }
    }
  }
}
</script>

<style scoped lang="less">
.black {
  padding-left: 20px;
}
</style>
